<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/static/iframe/import/_meta.jsp"></jsp:include>
<jsp:include page="/static/iframe/import/_header.jsp"></jsp:include>
<link rel="stylesheet" href="static/iframe/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="static/iframe/bootstrap/css/bootstrapValidator.min.css">
<title>更改密码</title>
<style>
.row {
	margin-right: 5px;
	margin-left: 5px;
	margin-top: 40px;
}

.form-bottom { 
  margin-top: 40px;
}
.form-group{
 margin-bottom: 30px;
}
</style>
</head>
<body>
<div style="width: 100%;">
<span class="c-red" style="font-size:15px; color:red; margin-left:7%;margin-top:5%">
<i class="glyphicon glyphicon-alert"></i> 您正在尝试修改密码,请谨慎操作!</span>
</div>
<div class="page-container">
		<div class="container-fluid">
			<form class="form-horizontal" method="post" id="pwdform">
				<div class="row">
				<input type="hidden" name="id" value="${id}">
					<div class="col-sm-4 col-md-4 col-lg-3 input-margin-bottom form-group">
						<div class="input-group input-group-md">
							<span class="input-group-addon"><span class="c-red">*&nbsp;</span>&nbsp;新&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码:</span>
							<input type="password" class="form-control" name="newPassword" placeholder="新密码"/>
						</div>
					</div>
					<div class="col-sm-4 col-md-4 col-lg-3 input-margin-bottom form-group">
						<div class="input-group input-group-md">
							<span class="input-group-addon"><span class="c-red">*&nbsp;</span>确认新密码:</span>
							<input type="password" class="form-control" name="realpassword" placeholder="确认新密码"/>
						</div>
					</div>
					</div>
						<div class="text-center mt-15" style="display: block;">
						<div class="tooltip-demo">
						<div class="form-bottom">
						<button class="btn btn-primary" type="submit">
							<i class="glyphicon glyphicon-ok"></i>&nbsp;提交
						</button>
						&nbsp;
						<button class="btn btn-success" type="reset" id="reset">
							<i class="glyphicon glyphicon-refresh"></i>&nbsp;重置
						</button>
						&nbsp; <a class="btn btn-white"
							href="javascript:layer_close()"
							target="_blank"><i class="glyphicon glyphicon-share-alt"></i>&nbsp;返回</a>
					   </div>
					   </div>
						</div>
			   </form>
		</div>
</div>
</body>
<jsp:include page="/static/iframe/import/_footer.jsp"></jsp:include>
<script type="text/javascript" src="static/iframe/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/iframe/bootstrap/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="static/plugins/window/layershow.js"></script>
 
 <script type="text/javascript">
  $(function(){
	  $("#pwdform").bootstrapValidator({
			feedbackIcons: {
							valid: 'glyphicon glyphicon-ok',
							invalid: 'glyphicon glyphicon-remove',
							validating: 'glyphicon glyphicon-refresh'
			},
			fields: {
				newPassword: {
	                message: '密码验证失败',
	                validators: {
	                    notEmpty: {
	                        message: '密码不能为空'
	                    },
	                    stringLength: {
	                        min: 6,
	                        max: 15,
	                        message: '密码长度必须在6到15位之间'
	                    },
	                    regexp: {
	                        regexp: /^[a-zA-Z0-9_]+$/,
	                        message: '密码只能包含大写、小写、数字和下划线'
	                    }
	                }
	            },
	            realpassword: {
	                message: '密码重复还没有验证',
	                validators: {
	                    notEmpty: {
	                        message: '密码重复不能为空'
	                    },
	                    stringLength: {
	                        min: 6,
	                        max: 15,
	                        message: '密码长度在6到15之间'
	                    },
	                    regexp: {
	                        regexp: /^[a-zA-Z0-9_]+$/,
	                        message: '密码只能包含大写、小写、数字和下划线'
	                    },
	                    identical: {
	                        field: 'newPassword',
	                        message: '两次密码不同请重新输入'   
	                    }
	                }
	            }
			}
			//做ajax请求用到
		}).on('success.form.bv', function(e) {
			e.preventDefault();
			var $form = $(e.target); //拿到form表单
			 layer.load(2,{time:1000});
			setTimeout(function(){
				//请求注册用户
			 	$.ajax({
					type:"post",
					url:"user/updatePassword",
					dataType:"json",
					data:$form.serialize(),
					success:function(result){
						if(result.flag){
							 layer.msg(result.msg,{time:1500,icon:1});
							 setTimeout(function(){
								 window.parent.location.reload();
							 },1500);
						}else{
							$("#pwdform").data('bootstrapValidator').resetForm();
							$("#passwords").val("");
							layer.msg(result.msg,{time:1500,icon:2});
						}
					},
					error:function(result) {
			              layer.msg(result.msg,{time:1500,icon:2});
					},
				});
			},1000);
	     });
		
		$("#reset").click(function(){
			$("#pwdform").data('bootstrapValidator').resetForm();
			
		});
   });
  
</script>
 
<!--[if lt IE 10]>
    <script type="text/javascript" src="static/plugins/js/input-placeholder/ieplaceholder.js"></script>
    <![endif]-->
</html>